{
语法百题 解题报告：
 http://git.oschina.net/et0662/sznoi-grammar/ 
}

function cmp(a:string; b:string):integer;
var
	i:integer;
begin
	i:=1;
	while(a[i]<>'#') and (b[i]<>'#') and (a[i]=b[i]) do
		inc(i);
	if(a[i]='#')then
		a[i]:=chr(0);
	if(b[i]='#')then
		b[i]:=chr(0);

	cmp:=ord(a[i])-ord(b[i]);
end;

var
	a:string;
	b:string;
begin
	readln(a);
	readln(b);
	if(cmp(a,b)>0)then
	begin
		writeln(b);
		writeln(a);
	end
	else
	begin
		writeln(a);
		writeln(b);
	end;
end.
